<template>
  <div class="shopcar">
    <div class="goods-list">
      <div class="mui-card" v-for="(item, i) in goodsList" :key="item.id">
        <div class="mui-card-content">
          <div class="mui-card-content-inner">
            <mt-switch
              v-model="$store.getters.getGoodSelected[item.id]"
              @change="selectedChanged(item.id, $store.getters.getGoodSelected[item.id])"
              ></mt-switch>
            <img :src="item.thumb_path" >
            <div class="info">
              <h1>{{item.title}}</h1>
              <p>
                <span class="price">￥{{item.sell_price}}</span>
                <numbox :initGoodsCount="$store.getters.getGoodsCount[item.id]" :goodsid="item.id"></numbox>
                <a href="javascript:;" @click="removegoods(item.id,i)">删除</a>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner jiesuan">
          <div class="left">
            <p>总计(不含运费)</p>
            <p>已勾选商品 <span class="red"></span>{{$store.getters.getSelectedCountAndAmount.selectedCount}}</span>件, 总价<span class="red">￥{{$store.getters.getSelectedCountAndAmount.amount}}</span></p>
          </div>
          <mt-button type="danger">去结算</mt-button>
        </div>
      </div>
    </div>
    <p>{{$store.getters.getGoodSelected}}</p>
  </div>
</template>
<script>
import numbox from '@/component/shopcar_box'
export default {
  data () {
    return {
      goodsList: []
    }
  },
  created () {
    this.getGoodsList()
  },
  methods: {
    getGoodsList () {
      var ids = []
      this.$store.state.cart.forEach(item => ids.push(item.id))
      if (ids.length <= 0) {
        return
      }
      this.axios.get('http://www.lovegf.cn:8899/api/goods/getshopcarlist/' + ids.join(',')).then(res => {
        if (res.status === 200) {
          console.log(res)
          this.goodsList = res.data.message
        }
      })
    },
    removegoods (id, index) {
      this.goodsList.splice(index, 1)
      this.$store.commit('removeCart', id)
    },
    selectedChanged (id, val) {
      // console.log(id+"-------"+val)
      this.$store.commit('updateGoodsChanged', {
        id: id,
        selected: val
      })
    }
  },
  components: {
    numbox
  }
}
</script>
<style lang='scss' scoped>
.shopcar {
  background-color: #eee;
  overflow: hidden;
  .goods-list {
    .mui-card-content-inner {
      display: flex;
      align-items: center;
    }
    img {
      width: 60px
    }
    h1 {
      font-size: 13px;
    }
    .info {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
  .jiesuan {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .red {
        color: red;
      }
    }
}
</style>
